var AUTO;
(function (AUTO) {
    var AjaxButton = (function () {
        function AjaxButton(element, fun_def, fun_para) {
            var me = $(this);
            me.off("click").on('click', function (event) {
                if (me.hasClass('disabled'))
                    return;
                me.addClass('disabled ');
                fun_def(fun_para).always(function () {
                    me.removeClass('disabled ');
                });
            });
        }
        return AjaxButton;
    }());
    AUTO.AjaxButton = AjaxButton;
    var AutoTimer = (function () {
        function AutoTimer(element, options) {
            this.cmd = { run: this.run, pause: this.pause, reset: this.reset };
            this.$el = $(element);
            if (_.isUndefined(options) || _.isObject(options)) {
                this.opt = {
                    text: '已执行<%=time%>秒。',
                    interval: 1000
                };
                $.extend(this.opt, options);
                this.opt.count = 1;
                this.tmpl = _.template(this.opt.text);
                this.opt.timer = setInterval(this.render.bind(this), this.opt.interval);
                this.$el.data('options', this);
            }
            else {
                var me = this.$el.data('options');
                me.cmd[options].call(me);
            }
        }
        AutoTimer.prototype.render = function () {
            this.$el.html(this.tmpl({ time: this.opt.count++ }));
        };
        AutoTimer.prototype.pause = function () {
            if (this.opt.timer) {
                clearInterval(this.opt.timer);
                this.opt.timer = null;
            }
        };
        AutoTimer.prototype.run = function () {
            if (!this.opt.timer) {
                this.opt.timer = setInterval(this.render.bind(this), this.opt.interval);
            }
        };
        AutoTimer.prototype.reset = function () {
            if (this.opt.timer) {
                clearInterval(this.opt.timer);
                this.opt.timer = null;
                this.opt.count = 0;
                this.render();
            }
        };
        return AutoTimer;
    }());
    AUTO.AutoTimer = AutoTimer;
})(AUTO || (AUTO = {}));
